﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EquipmentConfig
{
    public partial class WeirChannel : Form
    {
        public WeirChannel(double[] dbData)
        {
            InitializeComponent();
            double dbTemp1;
            double dbTemp2;
            double[] dbTemp = new double[256];
            dbTemp[0] = dbData[0];
            Bitmap bm = new Bitmap(512, 512);

            for (int i = 1; i < 256; i++)
            {
                dbTemp[i] = dbData[i] - dbData[i - 1];
            }

            //计算比例
            dbTemp1 = (double)512.0 / dbTemp.Max();
            dbTemp2 = Math.Round(dbTemp.Max() * 100000.0 / 1000.0, 3, MidpointRounding.AwayFromZero);
            lab1.Text = dbTemp2 + "m";

			for (int j = 0; j < 256; j++)   //行
			{
				int temp = Convert.ToInt32(dbTemp1 * dbTemp[j]);
				int x1 = (512 - temp) / 2;
				int x2 = 512 - x1;
                if (x1 > 512)
                {
                    x1 = 512;
                }
                if (x2 > 512)
                {
                    x2 = 512;
                }

                //中间填充列
                for (int m = x1; m < x2; m++)
				{
                    Color c = Color.FromArgb(120, 120, 200 - (256 - j) * 50 / 256);
                    bm.SetPixel(m, 512 - 1 - j * 2, c);
                    bm.SetPixel(m, 512 - 1 - (j * 2 + 1), c);
				}
			}
            pictureBox.Image = bm;
		}
    }
}
